package com.xoa.util;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import com.xoa.model.department.Department;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.FlowProcess;
import com.xoa.util.common.constants.DocumentConstants;

public class Lexical {

    public static String lexicalParse(String str, FlowProcess flowProcess, Users users, Department department){
        Calendar now = Calendar.getInstance();
          str = str.replace(DocumentConstants.year,now.get(Calendar.YEAR)+"");
          str = str.replace(DocumentConstants.month,now.get(Calendar.MONTH)+1+"");
          str = str.replace(DocumentConstants.day,now.get(Calendar.DAY_OF_MONTH)+"");
          str = str.replace(DocumentConstants.hour,now.get(Calendar.HOUR_OF_DAY)+"");
          str = str.replace(DocumentConstants.minute,now.get(Calendar.MINUTE)+"");
          str = str.replace(DocumentConstants.second,now.get(Calendar.SECOND)+"");
          str = str.replace(DocumentConstants.flow, flowProcess.getFlowName());
          str = str.replace(DocumentConstants.user,users.getUserName());
          str = str.replace(DocumentConstants.role,users.getUserPrivName());
          str = str.replace(DocumentConstants.flowName,users.getUserName());
          str = str.replace(DocumentConstants.shortDept,department.getDeptName());
        return str;
    }

    public Map<String, Object> allLexical(FlowProcess flowProcess){
        Map<String, Object> map = new HashMap<String, Object>();
        Calendar now = Calendar.getInstance();
        map.put(DocumentConstants.year, now.get(Calendar.YEAR));
        map.put(DocumentConstants.month,  (now.get(Calendar.MONTH) + 1));
        map.put(DocumentConstants.day, now.get(Calendar.DAY_OF_MONTH));
        map.put(DocumentConstants.hour, now.get(Calendar.HOUR_OF_DAY));
        map.put(DocumentConstants.minute, now.get(Calendar.MINUTE));
        map.put(DocumentConstants.second, now.get(Calendar.SECOND));
        map.put(DocumentConstants.flow, flowProcess.getFlowName());
       return map;
    }
}
